#pragma once

#ifdef _WIN32_WCE
#error "CHtmlView is not supported for Windows CE."
#endif 

#include "../_inc/def_interface.h"

// CWndMap html view

class CWndMap : public CHtmlView
{
	DECLARE_DYNCREATE(CWndMap)

private:
	enum 
	{
		EVENT_UPDATE = 0,
		EVENT_CHECK,
		EVENT_EXIT,
		EVENT_COUNT
	};
private:	
	DISPID					m_dispId;
	DISPID					m_dispIdRef;
	COleDispatchDriver		m_dispDriver;

	UINT					m_nTimer;

	float					m_fGpsN;
	float					m_fGpsE;

	float					m_fMapN;
	float					m_fMapE;
	int						m_nCarSpeed;

	BOOL					m_bInetReady;
	BOOL					m_bFirst;
	BOOL					m_bUpdate;

	CALLBACK_APP		m_pCallbackProc;
	void*				m_pCallbackParam;

	HANDLE				m_hThread;
	HANDLE				m_hEvent[EVENT_COUNT];


public:
	BOOL					m_bStarted;


private:
	void InitMapInter();
	BOOL SetGPSPosition(float fLatitude, float fLongitude, int nCarSpeed, BOOL bFirst=FALSE);

	void StartThread();
	void StopThread();

protected:
	CWndMap();           // protected constructor used by dynamic creation
	virtual ~CWndMap();

public:
	void UpdateWnd();	
	
	void SetGps(float fGpsN, float fGpsE, float fSpeed);

	void StartMap();
	void StopMap();

	BOOL CheckNetworkState();
	void SetState(BOOL bReady);
	void SetCallback(PCALLBACK_APP callbackProc, void* callbackParam);

	static UINT __stdcall _procThreadNetwork(LPVOID lpParam);
	void procThreadNetwork();

public:
#ifdef _DEBUG
	virtual void AssertValid() const;
	virtual void Dump(CDumpContext& dc) const;
#endif

protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	
	DECLARE_MESSAGE_MAP()

public:
	virtual void OnInitialUpdate();
	virtual BOOL PreTranslateMessage(MSG* pMsg);
	afx_msg void OnShowWindow(BOOL bShow, UINT nStatus);
	afx_msg void OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized);
	afx_msg void OnTimer(UINT nIDEvent);
	afx_msg void OnDestroy();
	afx_msg void OnPaint();
};

extern CWndMap* g_pWndMap;

